# 需求: 定义一个方法,传入一个数字,得到这个数字和数字前两位加后两位数组成的列表
arr = [1, 2]


# 页码: 从0开始(-1)
def get_middle_range(arr, num):
    # 如果数组长度小于等于5, 就直接返回整个数组
    if len(arr) <= 5:
        return arr
    max_index = len(arr) - 1
    # 动态指定索引
    index1 = None
    index2 = None
    index3 = None
    index4 = None
    index5 = None
    # 9 其实是请求第10页
    # 目标: 8 9 10 1 2

    # 9
    # 最后五个索引:                max_index-1      max_index
    # max_index - 2 7
    if num >= max_index - 2:
        index1 = max_index - 4
        index2 = max_index - 3
        index3 = max_index - 2
        index4 = max_index - 1
        index5 = max_index
    # 6
    # 目标: 5 6 7 8 9
    # 目标索引: 4 5 6 7 8
    elif 2 < num < max_index - 2:
        index1 = num - 2
        index2 = num - 1
        index3 = num
        index4 = num + 1
        index5 = num + 2
    # 2
    # 目标: 1 2 3 4 5
    # 目标索引: 0 1 2 3 4
    elif num <= 2:
        index1 = 0
        index2 = 1
        index3 = 2
        index4 = 3
        index5 = 4

    return [
        arr[index1],
        arr[index2],
        arr[index3],
        arr[index4],
        arr[index5],
    ]


# arr1 = f(arr, 5)
# arr1 = f(arr, 9)
# arr1 = f(arr, 8)
# arr1 = f(arr, 7)
# arr1 = f(arr, 6)
# arr1 = f(arr, 2)
# arr1 = f(arr, 1)
print(get_middle_range(arr, -1))
print(get_middle_range(arr, 0))
print(get_middle_range(arr, 1))
print(get_middle_range(arr, 2))
print(get_middle_range(arr, 3))
print(get_middle_range(arr, 4))
print(get_middle_range(arr, 5))
print(get_middle_range(arr, 6))
print(get_middle_range(arr, 7))
print(get_middle_range(arr, 8))
print(get_middle_range(arr, 9))
print(get_middle_range(arr, 10))
print(get_middle_range(arr, 11))
